<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

class All extends CI_Model {

    function login($login) {
        $this->db->where('username', $login['username']);
        $this->db->where('password', $login['password']);
        $this->db->where('type', 'admin');
        $s = $this->db->get('user');
        if ($s->num_rows() > 0) {
            return $s->result_array();
        }
    }

    function profile($username) {
        $this->db->where('username', $username);
        $pr = $this->db->get('user');
        if ($pr->num_rows > 0) {
            return $pr->result();
        }
    }

    function upd_pass($data) {
        $this->db->where('username', $data['username']);
        $this->db->update('user', $data);
    }

    function hapusdata($id) {
        $this->db->delete('user', array('id' => $id));
    }

    function ambiluser() {
        $ambiluser = $this->db->get('user');
        if ($ambiluser->num_rows() > 0) {
            foreach ($ambiluser->result() as $data) {
                $hasil[] = $data;
            }
            return $hasil;
        }
    }

    function user() {
        $as = $this->db->get('user');
        if ($as->num_rows() > 0) {
            return $as->result();
        }
    }

    function add_user($user) {
        $this->db->insert('user', $user);
    }

    function del_user($id) {
        $this->db->where('id', $id);
        $this->db->delete('user');
    }

    function ubah_user($id) {
        $this->db->where('id', $id);
        $usr = $this->db->get('user');
        if ($usr->num_rows > 0) {
            return $usr->result();
        }
    }

    function update_user($update) {
        $this->db->where('username', $update['username']);
        $this->db->update('user', $update);
    }

}

?>